package edu.ccut.saturn.studio.logic.model.saturn;

import java.util.ArrayList;
import java.util.List;

public class SaturnValidate implements Comparable<SaturnValidate> {

	public boolean equals(SaturnValidate validate) {
		if (this.key.equals(((SaturnValidate) validate).getKey())
				&& this.name.equals(((SaturnValidate) validate).getName())
				&& this.validateClass.equals(((SaturnValidate) validate)
						.getValidateClass())
				&& this.description.equals(((SaturnValidate) validate)
						.getDescription())
				&& this.jsMethodName.equals(((SaturnValidate) validate)
						.getJsMethodName())
				&& this.customJsMethod.equals(((SaturnValidate) validate)
						.getCustomJsMethod())
				&& this.isModifyArg(((SaturnValidate) validate))) {
			return true;
		}
		return false;
	}

	private boolean isModifyArg(SaturnValidate validate) {
		for (SaturnArg arg : this.args) {
			for (SaturnArg newArg : ((SaturnValidate) validate).getArgs()) {
				if (arg.equals(newArg) == false) {
					return false;
				}
			}
		}
		return true;
	}

	private String id = "";

	private String key = "";

	private String name = "";

	private String validateClass = "";

	private String description /*validateTypeInfo*/= "";

	private String jsMethodName = "";

	private String customJsMethod = "";

	private String validateType = "";
	

	

	private List<SaturnArg> args = new ArrayList<SaturnArg>();

	private List<ErrorInfo> errorInfos = new ArrayList<ErrorInfo>();

	private List<String> eventInfos = new ArrayList<String>();

	private List<SaturnValidate> validates = new ArrayList<SaturnValidate>();

	public SaturnValidate() {

	}

	public SaturnValidate(SaturnValidate saturnValidate) {
		this.id = saturnValidate.id;
		this.key = saturnValidate.key;
		this.name = saturnValidate.name;
		this.validateClass = saturnValidate.validateClass;
		this.description = saturnValidate.description;
		this.args = saturnValidate.args;
		this.errorInfos = saturnValidate.errorInfos;
		this.eventInfos = saturnValidate.eventInfos;
		this.jsMethodName = saturnValidate.jsMethodName;
		this.customJsMethod = saturnValidate.customJsMethod;
		this.validateType = saturnValidate.validateType;

		// this.errorInfo=saturnValidate.errorInfo;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getKey() {
		return key;
	}

	public void setKey(String key) {
		this.key = key;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getValidateClass() {
		return validateClass;
	}

	public void setValidateClass(String validateClass) {
		this.validateClass = validateClass;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public List<SaturnArg> getArgs() {
		return args;
	}

	public void setArgs(List<SaturnArg> args) {
		this.args = args;
	}

	public List<SaturnValidate> getValidates() {
		return validates;
	}

	public void setValidates(List<SaturnValidate> validates) {
		this.validates = validates;
	}

	@Override
	public String toString() {
		return "";
	}

	public String getJsMethodName() {
		return jsMethodName;
	}

	public void setJsMethodName(String jsMethodName) {
		this.jsMethodName = jsMethodName;
	}

	public String getCustomJsMethod() {
		return customJsMethod;
	}

	public void setCustomJsMethod(String customJsMethod) {
		this.customJsMethod = customJsMethod;
	}

	public int compareTo(SaturnValidate parameter) {
		if (this.id != null) {
			int idInt = Integer.parseInt(id);
			int parameterIdInt = Integer.parseInt(parameter.getId());
			if (idInt > parameterIdInt) {
				return 1;
			} else if (idInt == parameterIdInt) {
				return 0;
			}
		}
		return -1;
	}

	public List<?> getChild() {
		return this.args;
	}

	public void setChild(List<?> list) {

	}

	public List<ErrorInfo> getErrorInfos() {
		return errorInfos;
	}

	public void setErrorInfos(List<ErrorInfo> errorInfos) {
		this.errorInfos = errorInfos;
	}

	public List<String> getEventInfos() {
		return eventInfos;
	}

	public void setEventInfos(List<String> eventInfos) {
		this.eventInfos = eventInfos;
	}

	public String getValidateType() {
		return validateType;
	}

	public void setValidateType(String validateType) {
		this.validateType = validateType;
	}

}
